From f297ef653008b47fdaa4eebbccf2705f3d0996a8 Mon Sep 17 00:00:00 2001
From: Fabrice Fontaine <fontaine.fabrice@gmail.com>
Date: Wed, 10 Nov 2021 23:14:54 +0100
Subject: [PATCH] fix musl build on riscv

Fix the following build failure raised with musl:

../../gdbserver/linux-riscv-low.cc: In function 'void riscv_fill_fpregset(regcache*, void*)':
../../gdbserver/linux-riscv-low.cc:140:19: error: 'ELF_NFPREG' was not declared in this scope; did you mean 'ELF_NGREG'?
  140 |   for (i = 0; i < ELF_NFPREG - 1; i++, regbuf += flen)
      |                   ^~~~~~~~~~
      |                   ELF_NGREG

musl fixed the issue with
https://git.musl-libc.org/cgit/musl/commit/?id=e5d2823631bbfebacf48e1a34ed28f28d7cb2570

Fixes:
 - http://autobuild.buildroot.org/results/16b19198980ce9c81a618b3f6e8dc9fe28247a28

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
---
 gdb/nat/riscv-linux-tdesc.c  | 5 +++++
 gdbserver/linux-riscv-low.cc | 5 +++++
 2 files changed, 10 insertions(+)

diff --git a/gdb/nat/riscv-linux-tdesc.c b/gdb/nat/riscv-linux-tdesc.c
index d676233cc31..b620aab5b72 100644
--- a/gdb/nat/riscv-linux-tdesc.c
+++ b/gdb/nat/riscv-linux-tdesc.c
@@ -31,6 +31,11 @@
 # define NFPREG 33
 #endif
 
+/* Work around musl breakage since version 1.1.24.  */
+#ifndef ELF_NFPREG
+# define ELF_NFPREG 33
+#endif
+
 /* See nat/riscv-linux-tdesc.h.  */
 
 struct riscv_gdbarch_features
diff --git a/gdbserver/linux-riscv-low.cc b/gdbserver/linux-riscv-low.cc
index 4c251bb179c..77a48ac9ee1 100644
--- a/gdbserver/linux-riscv-low.cc
+++ b/gdbserver/linux-riscv-low.cc
@@ -30,6 +30,11 @@
 # define NFPREG 33
 #endif
 
+/* Work around musl breakage since version 1.1.24.  */
+#ifndef ELF_NFPREG
+# define ELF_NFPREG 33
+#endif
+
 /* Linux target op definitions for the RISC-V architecture.  */
 
 class riscv_target : public linux_process_target
-- 
2.43.0

